package com.github.catvod.spider.merge;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.impl.StaticLoggerBinder;

/* loaded from: classes.dex */
public final class bv {
    static volatile int h;
    static final Gr V0 = new Gr();
    static final l6 j = new l6();
    static boolean q = r.oC("slf4j.detectLoggerNameMismatch");
    private static final String[] I = {"1.6", "1.7"};
    private static String oC = "org/slf4j/impl/StaticLoggerBinder.class";

    private bv() {
    }

    private static void BQ() {
        Gr gr = V0;
        synchronized (gr) {
            gr.I();
            for (Aq aq : gr.q()) {
                aq.I(Qy(aq.getName()));
            }
        }
    }

    private static boolean F8() {
        String BQ = r.BQ("java.vendor.url");
        if (BQ == null) {
            return false;
        }
        return BQ.toLowerCase().contains("android");
    }

    private static void GM(Set<URL> set) {
        if (oq(set)) {
            r.j("Class path contains multiple SLF4J bindings.");
            Iterator<URL> it = set.iterator();
            while (it.hasNext()) {
                r.j("Found binding in [" + it.next() + "]");
            }
            r.j("See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
        }
    }

    static void I(Throwable th) {
        h = 2;
        r.q("Failed to instantiate SLF4J LoggerFactory", th);
    }

    private static void PD(UW uw) {
        if (uw == null) {
            return;
        }
        Aq h2 = uw.h();
        String name = h2.getName();
        if (h2.j()) {
            throw new IllegalStateException("Delegate logger cannot be null at this state.");
        }
        if (h2.V0()) {
            return;
        }
        if (h2.h()) {
            h2.q(uw);
        } else {
            r.j(name);
        }
    }

    private static final void PU() {
        try {
            String str = StaticLoggerBinder.REQUESTED_API_VERSION;
            boolean z = false;
            for (String str2 : I) {
                if (str.startsWith(str2)) {
                    z = true;
                }
            }
            if (z) {
                return;
            }
            r.j("The requested version " + str + " by your slf4j binding is not compatible with " + Arrays.asList(I).toString());
            r.j("See http://www.slf4j.org/codes.html#version_mismatch for further details.");
        } catch (NoSuchFieldError unused) {
        } catch (Throwable th) {
            r.q("Unexpected problem occured during version sanity check", th);
        }
    }

    public static vn Qy(String str) {
        return W().h(str);
    }

    private static void V0(UW uw, int i) {
        if (uw.h().h()) {
            j(i);
        } else {
            if (uw.h().V0()) {
                return;
            }
            q();
        }
    }

    public static Za W() {
        if (h == 0) {
            synchronized (bv.class) {
                if (h == 0) {
                    h = 1;
                    iU();
                }
            }
        }
        int i = h;
        if (i == 1) {
            return V0;
        }
        if (i == 2) {
            throw new IllegalStateException("org.slf4j.LoggerFactory in failed state. Original exception was thrown EARLIER. See also http://www.slf4j.org/codes.html#unsuccessfulInit");
        }
        if (i == 3) {
            return StaticLoggerBinder.getSingleton().getLoggerFactory();
        }
        if (i == 4) {
            return j;
        }
        throw new IllegalStateException("Unreachable code");
    }

    private static final void h() {
        Set<URL> set = null;
        try {
            try {
                if (!F8()) {
                    set = oC();
                    GM(set);
                }
                StaticLoggerBinder.getSingleton();
                h = 3;
                j5(set);
            } catch (Exception e) {
                I(e);
                throw new IllegalStateException("Unexpected initialization failure", e);
            } catch (NoClassDefFoundError e2) {
                if (!t(e2.getMessage())) {
                    I(e2);
                    throw e2;
                }
                h = 4;
                r.j("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
                r.j("Defaulting to no-operation (NOP) logger implementation");
                r.j("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.");
            } catch (NoSuchMethodError e3) {
                String message = e3.getMessage();
                if (message != null && message.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) {
                    h = 2;
                    r.j("slf4j-api 1.6.x (or later) is incompatible with this binding.");
                    r.j("Your binding is version 1.5.5 or earlier.");
                    r.j("Upgrade your binding to version 1.6.x.");
                }
                throw e3;
            }
        } finally {
            i4();
        }
    }

    private static void i4() {
        BQ();
        y();
        V0.V0();
    }

    private static final void iU() {
        h();
        if (h == 3) {
            PU();
        }
    }

    private static void j(int i) {
        r.j("A number (" + i + ") of logging calls during the initialization phase have been intercepted and are");
        r.j("now being replayed. These are subject to the filtering rules of the underlying logging system.");
        r.j("See also http://www.slf4j.org/codes.html#replay");
    }

    private static void j5(Set<URL> set) {
        if (set == null || !oq(set)) {
            return;
        }
        r.j("Actual binding is of type [" + StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr() + "]");
    }

    private static boolean n(Class<?> cls, Class<?> cls2) {
        return !cls2.isAssignableFrom(cls);
    }

    static Set<URL> oC() {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        try {
            ClassLoader classLoader = bv.class.getClassLoader();
            Enumeration<URL> systemResources = classLoader == null ? ClassLoader.getSystemResources(oC) : classLoader.getResources(oC);
            while (systemResources.hasMoreElements()) {
                linkedHashSet.add(systemResources.nextElement());
            }
        } catch (IOException e) {
            r.q("Error getting resources from path", e);
        }
        return linkedHashSet;
    }

    private static boolean oq(Set<URL> set) {
        return set.size() > 1;
    }

    private static void q() {
        r.j("The following set of substitute loggers may have been accessed");
        r.j("during the initialization phase. Logging calls during this");
        r.j("phase were not honored. However, subsequent logging calls to these");
        r.j("loggers will work as normally expected.");
        r.j("See also http://www.slf4j.org/codes.html#substituteLogger");
    }

    private static boolean t(String str) {
        if (str == null) {
            return false;
        }
        return str.contains("org/slf4j/impl/StaticLoggerBinder") || str.contains("org.slf4j.impl.StaticLoggerBinder");
    }

    public static vn u(Class<?> cls) {
        Class<?> h2;
        vn Qy = Qy(cls.getName());
        if (q && (h2 = r.h()) != null && n(cls, h2)) {
            r.j(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", Qy.getName(), h2.getName()));
            r.j("See http://www.slf4j.org/codes.html#loggerNameMismatch for an explanation");
        }
        return Qy;
    }

    private static void y() {
        LinkedBlockingQueue<UW> j2 = V0.j();
        int size = j2.size();
        ArrayList<UW> arrayList = new ArrayList(128);
        int i = 0;
        while (j2.drainTo(arrayList, 128) != 0) {
            for (UW uw : arrayList) {
                PD(uw);
                int i2 = i + 1;
                if (i == 0) {
                    V0(uw, size);
                }
                i = i2;
            }
            arrayList.clear();
        }
    }
}
